<%@ page isELIgnored="false" language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core_rt" %>

<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<link rel="stylesheet" type="text/css" href="<%=basePath%>img/from.css">
<script type="text/javascript">
var type = ["","cardUnLoss","cardLoss","cardDel"];
type=type['${type }'];
	function readCardInfo(){
		var cardid = findNormalCard();
		if(cardid){
			$('#abaid').val(cardid);
			return true;
		}return false;
	}
	function queryInfo(){
		var r = $('#ff').form('validate');
		if(!r) {
			return false;
		}
		if($('#abaid').val()=='' && $('#ownercard').val()=='')
		{
			$.messager.alert('提示','一卡通卡号和有效证号必须输入一个。','info');
			return false;
		}
		$("#resultInfo").show();
		$.post("aba/"+type,$("#ff").serializeArray(),function(data){
			if (typeof(data.username) == "undefined") {
				$("#userInfo").hide();
			}else
			{
				$("#userInfo").show();
				$("#username").text(data.username);
				$("#ownercardText").text(data.ownercard);
				if(data.sex == "1")
				{
					$("#sex").text("男");
				}else if(data.sex == "0")
				{
					$("#sex").text("女");
				}else
				{
					$("#sex").text("不明");
				}		
				$("#telephone").text(data.telephone);			
			}

			
			if (typeof(data.aba) == "undefined") {
				$("#cardInfo").hide();
				$('#abaTable').datagrid('loadData', {total:0, rows:[]});   
				return;
			}
			function convert(){
				if('${type }'=="2"){
					return "开卡日期";
				}else{
					return "挂失日期";
				}
			}
			$("#cardInfo").show();
			$('#abaTable').datagrid({
				 singleSelect:true,//多选
				 striped: true,//奇偶行颜色不同
				 fitColumns: true,
				 rownumbers:true, //显示行号
				 columns:[[
				           {title:'卡号',field:'abaid',width:180,align:'center'},
				           {title:'userid',field:'userid',width:180,align:'center',hidden:true},
				           {title:'cardpassword',field:'cardpassword',width:180,align:'center',hidden:true},
				           {title:'version',field:'version',width:180,align:'center',hidden:true},
				           {title:'电子账户余额',field:'emoney',width:180,align:'center'},
				           {title:'电子钱包余额',field:'money',width:180,align:'center'},
				           {title:'losteddate',field:'losteddate',width:180,align:'center',hidden:true},
				           {title:'cardkey',field:'cardkey',width:180,align:'center',hidden:true},
		                   {title:convert(),field:'creatdatetime',width:180,align:'center',formatter:function(value,row,index){
		                	   if('${type }'=="2"){
		       					return row.creatdatetime;
			       				}else{
			       					return row.losteddate;
			       				}
	    					}},
		                   {title:'状态',field:'losted',width:180,
		    					formatter:function(value,row,index){
		    						if (row.losted==1) { 
		    							return "正常" ;
		    						}
		    						else if(row.losted == 2){ 
		    							return "挂失";
		    						}else{
		    							return "取消使用";
		    						}
		    					}
		    				},	
		                    {title:'是否有电子账户',field:'eflag',width:180,align:'center',
		    					formatter:function(value,row,index){
		    						if (row.eflag==true) { 
		    							return "是";
		    						}else{
		    							return "否";
		    						}
		    					}
		    				}
				           ]]
			});
			$('#abaTable').datagrid('loadData', data.aba);   
		});
	}
	
    //更新
    function changeCard(){
		var rows = $('#abaTable').datagrid('getSelections');
		if(rows.length==0){
			$.messager.alert('提示',"请选择你要"+'${operName }'+"的卡",'info');
			return;
		}
		if(rows[0].losted == '${type }'){
			$.messager.alert('提示',"此卡已${operName }.",'info');
			return;
		}
		if('${type }'== 3){
			if(rows[0].losted !=2){
				$.messager.alert('提示',"账户解除需挂失，并在挂失7天后操作.",'info');
				return false;
			}
			$.post('aba/cardDelCardChangePopWindow?lostedDate='+rows[0]["losteddate"],function(data){
	        	if(data.mes=="0"){
	        		$.messager.alert('提示',"卡片挂失未到7天.",'info');
	        		return false;
	        	}else{
	        		rows[0]["creatuserid"] = '<sec:authentication property="name"/>';
	        		rows[0].ltype = '${type }';
	        		rows[0].delmoney =rows[0].money+rows[0].emoney;
	        		$.messager.confirm('退款确认', '需要退还用户总金额<font color=red>'+rows[0].delmoney+'</font>,是否确认?', function(r){
       				if (r){
		        		if(rows[0].eflag){
		        			prompt(rows[0]);
		        		}else{
	       					$.post("aba/"+type+"cardOper",rows[0],function(data){
	   	        				$.messager.alert('提示',data.mes,'info');
	   	        			});
	       					clearForm();
		        		}
       				}
        			});
	        		return false;
	        	}
	    	});
			return false;
		}
		rows[0]["creatuserid"] = '<sec:authentication property="name"/>';
		rows[0].ltype = '${type }';
		if(rows[0].eflag){
			prompt(rows[0]);
		}else{
			$.post("aba/"+type+"cardOper",rows[0],function(data){
				$.messager.alert('提示',data.mes,'info');
			});
			clearForm();
		}
	}  
    function prompt(row){

		$.messager.prompt('请输入电子账户密码', '请输入电子账户密码密码', function(r){
			if (r){
				row.newPass = r;
				$.post("aba/"+type+"cardOper",row,function(data){
					$.messager.alert('提示',data.mes,'info');
				});
				clearForm();
			}else{
				return ;
			}

		});

	}
    
	//清空查询条件
	function clearForm(){
		$('#ff').form('clear');
		$("#resultInfo").hide();
	}
</script>
<div style="background:#fafafa;padding:10px;">
	<div style="padding:3px 2px;margin-bottom:10px;border-bottom:1px solid #ccc"><div>${operName }</div></div>
	<div style="background:#fafafa;">
	    <form id="ff" method="post">
			<table width="100%">
				<tr>
				 <td>一卡通卡号：<input id="abaid" name="abaid" style="width: 150"></input></td>
				 <td>有效证件号：<input id="ownercard" name="ownercard" style="width: 150"></input></td>
				</tr>
			</table>
	    </form>
	</div>
	<div style="margin:10px 0;">
		<a href="#" class="easyui-linkbutton" onclick="readCardInfo()" iconCls="icon-search">读卡</a> 
		<a href="#" class="easyui-linkbutton" onclick="queryInfo()" iconCls="icon-search">查询</a> 
		<a href="#" class="easyui-linkbutton" onclick="clearForm()" iconCls="icon-search">清空</a> 
	</div>
</div>
<div id="resultInfo" style="background:#fafafa;padding:10px;display:none;">
	<div id="userInfo"  style="background:#fafafa;">
		<table width="100%">
			<tr>
			 <td>姓名：</td><td id="username" width="200px"></td>
			 <td>有效证件号：</td><td id="ownercardText" width="200px"></td>
			 <td>性别：</td><td id="sex" width="200px"></td>
			 <td>移动电话：</td><td id="telephone" width="200px"></td>
			</tr>
		</table>
	</div>
	<div id="cardInfo"  style="padding:10" id="tabdiv">
		<table id="abaTable"></table>
		<div style="margin:10px 0;">
		 <a href="#" class="easyui-linkbutton"  iconCls="icon-search" onclick='changeCard()'>${operName }</a> 
	    </div>	
	</div>
</div>